﻿using System;
using System.ComponentModel.Composition;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Silverlight.Weblog.Client.CoreBL.Widgets;
using Silverlight.Weblog.Client.Default.Widgets.BaseUI;
using Silverlight.Weblog.Client.Default.Widgets.DefaultTheme;

namespace Silverlight.Weblog.Client.Default.Widgets
{
    [Export(typeof(IBlogWidget))]
	public partial class TwitterSidebarWidget : UserControlBase, IDefaultSidebarWidget
	{
        public ITwitterSidebarWidgetViewModel ViewModel { get; set; }

		public TwitterSidebarWidget()
		{
			// Required to initialize variables
			InitializeComponent();

            this.MouseEnter += (s, args) => GoToState(Expanded.Name);
		    this.MouseLeave += (s, args) => GoToState(Collapsed.Name);
			
			 scrollViewer.MouseWheel += new MouseWheelEventHandler(scrollViewer_MouseWheel);
		}
		
		private void scrollViewer_MouseWheel(object sender, MouseWheelEventArgs e)
        {
			var oldValue = scrollViewer.VerticalOffset;
            var NewVerticalOffset = scrollViewer.VerticalOffset - 3*e.Delta;
            scrollViewer.ScrollToVerticalOffset(NewVerticalOffset);
            if (oldValue > 0 && oldValue < scrollViewer.ScrollableHeight)
			{
				e.Handled = true;
			}
        }

	    #region Implementation of IDefaultSidebarWidget

	    public int Priority
	    {
            get { return 500; }
	    }

	    public string HeadlineText
	    {
	        get { return "Twitter"; }
	    }

	    #endregion
	}

}